Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination support #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

kenodegard
Copy link

Added pagination support for a few of the known pagination calls.

I know there are several other calls that also have pagination.

This also suggests that instead of adding pagination support manually as I have done in this commit to every single call that has pagination maybe some kind of decorator logic should be introduced.

Current implementation:

def get_event_attendees(self, event_id, status=None, changed_since=None, page=None):
    data = {}
    if status:
        data['status'] = status
    if changed_since:
        data['changed_since'] = changed_since
    if page:
        data['page'] = page
    return self.get("/events/{0}/attendees/".format(event_id), data=data)

Alternative implementation:

from functools import wraps

def data(arg, optional=True):
    def func(f):
        @wraps(f)
        def _(self, event_id, *args, data=None, **kwargs):
            if data is None:
                data = {}
            # arg is either in kwargs OR args[0]
            if arg in kwargs:
                # found arg in kwargs
                data[arg] = kwargs[arg]
                del kwargs[arg]
            elif len(args) > 0:
                # found arg in args
                data[arg] = args[0]
                args = args[1:]
            elif not optional:
                # did not find arg and it is required
                raise TypeError("missing required argument {0}".format(arg))
            return f(self, event_id, *args, data=data, **kwargs)
        return _
    return func

@data("status")
@data("changed_since")
@data("page")
def get_event_attendees(self, event_id, data={}):
    return self.get("/events/{0}/attendees/".format(event_id), data=data)

Added pagination support for a few of the known pagination calls.
@kenodegard
Copy link
Author

Related to #18

@mwvolo
Copy link

mwvolo commented Feb 12, 2020

WHY IS THIS NOT MERGED?? 😩

@dcwiggin
Copy link

I just finished a script for us to pull down all my org's eventbrite data, and low and behold. I am completely stuck until this is ready. What is the hold up? Why no pagination on a clearly paginated response?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants